<?php
namespace app\admin\controller;

use think\Controller;
use Common\Controller\BaseController;
use think\Request;
use think\Session;


class Index extends Controller
{
//后台首页开始
    public function index()
    {
        $user = session('user');
        //dump($user);exit;
        if($user){
            $name['name'] = session('user.name');
            //dump($name);exit;
            $res = db('admin')->where($name)->find();
            $this->assign('list',$res);
            return $this->fetch();
        }else{
            header("Refresh:1;url=login");
        }
    }
//后台首页结束

    //跳转登陆页面开始
    public function login(){
        $user = session('user');
        //dump($user);exit;

        if($user){
            header("Refresh:1;url=index");
        }

        return $this->fetch();
    }
    //跳转登陆页面结束
    //验证登陆开始开始
    public function loginfind(){
        $user = session('user');
        //dump($user);exit;
        //return show(1, '登录失败');

        if($user){
            header("Refresh:1;url=index");
        }

        if(!$_POST){
            echo "<script>alert('请输入正确的账号账号密码');location.href='login';</script>";
           // $this->success('请输入正确的账号账号密码','login');
        }
       $data['name'] = trim($_POST['username']);
       $data['password']=md5(md5(trim($_POST['password'])));

        $res=db('admin')->where($data)->find();
       if($res['password'] == $data['password']){
           $data = array(
               'admin_id' => $res['id'],
               'name' => $res['name'],
               'jurisdiction' => $res['jurisdiction']
           );
           session('user',$data);  //设置session
           return ['code'=>1,'msg'=>'登录成功'];
        }else{
           return ['code'=>0,'msg'=>'登录失败'];
        }
    }
    //验证登陆开始结束
    //注销登录开始
    public function loginout(){
        session('user', null);
        echo "<script>alert('退出登陆成功');location.href='login';</script>";
    }
    //注销登录结束
//快递详情页开始
public function express(){
    $user = session('user');
    //dump($user);exit;

    if(!$user){
        header("Refresh:1;url=login");
    }
    $operation['operation']=$user = session('user.name');
    $res=db('user')->where($operation)->paginate(10);
    $page =  $res->render();
    $this->assign('page',$page);
    $this->assign('list',$res);
    return $this->fetch();
}
    public function expresswhole(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }
        $res=db('user')->paginate(10);
        $page =  $res->render();
        $this->assign('page',$page);
        $this->assign('list',$res);
        return $this->fetch();
    }
//快递详情页结束

//快递详修改页开始
public function express_det(){
    $user = session('user');
    if(!$user){
        header("Refresh:1;url=login");
    }
    $data['id'] = trim(input('id'));
    $res=db('user')->where($data)->find();
    $this->assign('list',$res);
    return $this->fetch();
}
//快递详修改页开始
public function expressupdate(){
    $user = session('user');
    //dump($user);exit;

    if(!$user){
        header("Refresh:1;url=login");
    }
if(!$_POST) {
    echo "<script>alert('提交不能为空');location.href='express';</script>";
    //$this->success('提交不能为空', 'express');
}
//dump($_POST);exit;
    $id['id'] = trim($_GET['id']);

    $data = $_POST;
    $data['operation'] = session('user.name');
    $data['time'] = time();
    //dump($data);exit;
    $res=db('user')->where($id)->update($data);
    if($res){
        echo "<script>alert('更新信息成功');location.href='express';</script>";
        //return ['code'=>1,'msg'=>'更新信息成功'];
    }else{
        echo "<script>alert('更新信息失败');location.href='express';</script>";
    }
}
//快递修改页结束


//快递添加开始
public function express_insert(){
    $user = session('user');
    //dump($user);exit;

    if(!$user){
        header("Refresh:1;url=login");
    }
    return $this->fetch();
}
public function expressadd(){
    $user = session('user');
    //dump($user);exit;

    if(!$user){
        header("Refresh:1;url=login");
    }
    if(!$_POST) {
        $this->success('提交不能为空', 'express');
    }
    //$data = $_POST;
    //dump($_POST);exit;
    $res=db('user')->insert($data);
    if($res){
        echo "<script>alert('添加信息成功');location.href='express';</script>";
        //return ['code'=>1,'msg'=>'添加信息成功'];
    }else{
        echo "<script>alert('添加信息失败');location.href='express';</script>";
        //return ['code'=>0,'msg'=>'添加信息失败'];
    }
}
//快递添加结束

//快递详情删除开始
    public function expressdelete(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_GET){
            $this->success('提交不能为空','express');
        }
        $data['id'] = trim($_GET['id']);
        $res=db('user')->where($data)->delete();
        if($res){
            echo "<script>alert('删除信息成功');javascript:history.go(-1);</script>";
            //return ['code'=>1,'msg'=>'删除信息成功'];

        }else{
            echo "<script>alert('删除信息失败');javascript:history.go(-1);</script>";
            //return ['code'=>0,'msg'=>'删除信息失败'];

        }
    }
//快递详情删除结束
//快递员详情页开始
    public function member(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }
        //$map = array();

        $operation['operation']=$user = session('user.name');
        $res=db('member')->where($operation)->paginate(10);
        //$res = VideoModel::Paging($map,10);
        $page =  $res->render();
        $this->assign('page',$page);
        $this->assign('list',$res);
        return $this->fetch();

    }
    public function memberwhole(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }
        //$map = array();
        $res=db('member')->paginate(10);
        //$res = VideoModel::Paging($map,10);
        $page =  $res->render();
        $this->assign('page',$page);
        $this->assign('list',$res);
        return $this->fetch();

    }
//快递员详情页结束
//管理员修改密码开始
public function save_pwd(){
    $user = session('user');
    //dump($user);exit;

    if(!$user){
        header("Refresh:1;url=login");
    }
    $res=db('admin')->select();
    $this->assign('list',$res);
    return $this->fetch();
}
public function save_pwdupdata(){
    $user = session('user');
    //dump($user);exit;

    if(!$user){
        header("Refresh:1;url=login");
    }

    if(!$_POST){
        echo "<script>alert('提交不能为空');location.href='save_pwd';</script>";

    }
    $name['name'] = session('user.name');

    $orpassword['orpassword'] = md5(md5(trim($_POST['orpassword'])));
    $password['password'] = md5(md5(trim($_POST['password'])));
    $repassword['repassword'] = md5(md5(trim($_POST['repassword'])));
    $res = db('admin')->where($name)->find();

    if($res['password'] != $orpassword['orpassword']){
        return ['code'=>1,'msg'=>'原密码不正确'];
    }
    //dump($name);exit;
    $sql = db('admin')->where($name)->update($password);
    if($sql){
        return ['code'=>2,'msg'=>'修改成功'];
        //echo "<script>alert('修改成功');location.href='save_pwd';</script>";
    }else{
        return ['code'=>3,'msg'=>'修改失败'];
        //echo "<script>alert('修改失败');location.href='save_pwd';</script>";
    }
    }
//管理员修改密码结束

//添加快递员开始
public function member_insert(){
    $user = session('user');
    //dump($user);exit;

    if(!$user){
        header("Refresh:1;url=login");
    }
    return $this->fetch();
}
    public function memberadd(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_POST) {
            echo "<script>alert('提交不能为空');location.href='memberadd';</script>";
        }
        $na['name'] = trim($_POST['name']);
        $res = db('member')->where($na)->find();
        if($na['name'] == $res['name']){
            echo "<script>alert('添加账号重复');location.href='member_insert';</script>";
        }
        $data['name'] = trim($_POST['name']);
        $data['password'] = md5(md5(trim($_POST['password'])));
        $data['signname'] = trim($_POST['signname']);
        $expresspoint['name'] = session('user.name');
		$kd = db('admin')->where($expresspoint)->find();
        $data['expresspoint'] = trim($kd['expresspoint']);
        $data['operation'] = session('user.name');
        $data['time'] = time();
        $res=db('member')->insert($data);
        if($res){
            //return ['code'=>1,'msg'=>'添加信息成功'];
            echo "<script>alert('添加信息成功');location.href='member';</script>";
        }else{
            //return ['code'=>0,'msg'=>'添加信息失败'];
            echo "<script>alert('添加信息失败');location.href='member';</script>";
        }
    }
    //添加快递员结束
//快递员更新开始
public function member_det(){
    $user = session('user');
    //dump($user);exit;

    if(!$user){
        header("Refresh:1;url=login");
    }
    if(!$_GET) {
        echo "<script>alert('提交不能为空');location.href='member';</script>";
        //$this->success('提交不能为空', 'express');
    }
        $id['id']=trim($_GET['id']);
    $res=db('member')->where($id)->find();
    $this->assign('list',$res);
    return $this->fetch();
}
    public function memberupdate(){
        $user = session('user');
        //dump($user);exit;
        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_POST) {
            echo "<script>alert('提交不能为空');location.href='express';</script>";
            //$this->success('提交不能为空', 'express');
        }
        $id['id'] = trim($_GET['id']);
        //dump($_POST);exit;
        //$data = $_POST;
        $data['name'] = trim(input('name'));
        $data['password'] = md5(md5(trim(input('password'))));
        $data['signname'] = trim(input('signname'));
        $expresspoint['name'] = session('user.name');
		$kd = db('admin')->where($expresspoint)->find();
        $data['expresspoint'] = trim($kd['expresspoint']);
        $data['operation'] = session('user.name');
        $data['time'] = time();
        //dump($data);exit;
        $res=db('member')->where($id)->update($data);
        if($res){
            echo "<script>alert('更新信息成功');location.href='member';</script>";
            //return ['code'=>1,'msg'=>'更新信息成功'];

        }else{
            echo "<script>alert('更新信息失败');location.href='member';</script>";
            //return ['code'=>0,'msg'=>'更新信息失败'];

        }
    }
//快递员更新结束
//快递员删除开始
public function memberdelete(){
    $user = session('user');
    //dump($user);exit;

    if(!$user){
        header("Refresh:1;url=login");
    }
    if(!$_GET){
        $this->success('提交不能为空','member');
    }
    $data['id'] = trim($_GET['id']);
    $res=db('member')->where($data)->delete();
    if($res){
        echo "<script>alert('删除信息成功');javascript:history.go(-1);</script>";
        //return ['code'=>1,'msg'=>'删除信息成功'];

    }else{
        echo "<script>alert('删除信息失败');javascript:history.go(-1);</script>";
        //return ['code'=>0,'msg'=>'删除信息失败'];

    }
}
//快递员删除结束

//exel 导出开始
//中文导出开始
public function chinese(){
    $user = session('user');
    //dump($user);exit;
    if(!$user){
        header("Refresh:1;url=login");
    }
    //echo "<script>alert('中文导出开发中')</script>";
    //数据库字段
    //$list = array(array('id'=>1,'name'=>'du'),array('id'=>2,'name'=>'long'));
    $list = db('user')->select();
    //导出
    $path = dirname(__FILE__); //找到当前脚本所在路径
    vendor("PHPExcel.Classes.PHPExcel");
    vendor("PHPExcel.Classes.PHPExcel.Writer.IWriter");
    vendor("PHPExcel.Classes.PHPExcel.Writer.Abstract");
    vendor("PHPExcel.Classes.PHPExcel.Writer.Excel5");
    vendor("PHPExcel.Classes.PHPExcel.Writer.Excel2007");
    vendor("PHPExcel.Classes.PHPExcel.IOFactory");
    $objPHPExcel = new \PHPExcel();
    $objWriter = new \PHPExcel_Writer_Excel5($objPHPExcel);
    $objWriter = new \PHPExcel_Writer_Excel2007($objPHPExcel);


    // 实例化完了之后就先把数据库里面的数据查出来


    // 设置表头信息
    $objPHPExcel->setActiveSheetIndex(0)
        ->setCellValue('A1', 'id')
        ->setCellValue('B1', '发货姓名')
        ->setCellValue('C1', '发货手机号')
        ->setCellValue('D1', '发货城市')
        ->setCellValue('E1', '快递单号')
        ->setCellValue('F1', '发货地址')
        ->setCellValue('G1', '发件单位名称')
        ->setCellValue('H1', '运费金额')
        ->setCellValue('I1', '重量')
        ->setCellValue('J1', '数量')
        ->setCellValue('K1', '保险价格')
        ->setCellValue('L1', '揽收员工')
        ->setCellValue('M1', '总计费用')
        ->setCellValue('N1', '快递物品')
        ->setCellValue('O1', '收件人姓名')
        ->setCellValue('P1', '收件人手机号')
        ->setCellValue('Q1', '收件人地址')
        ->setCellValue('R1', '收件人单位名称')
        ->setCellValue('S1', '收件城市')
        ->setCellValue('T1', '签收人员');

    /*--------------开始从数据库提取信息插入Excel表中------------------*/

    $i=2;  //定义一个i变量，目的是在循环输出数据是控制行数
    $count = count($list);  //计算有多少条数据
    for ($i = 2; $i <= $count+1; $i++) {
        $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $list[$i-2]['id']);
        $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $list[$i-2]['hairname']);
        $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $list[$i-2]['hairphone']);
        $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $list[$i-2]['haircity']);
        $objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $list[$i-2]['oddnumbers']);
        $objPHPExcel->getActiveSheet()->setCellValue('F' . $i, $list[$i-2]['hairaddress']);
        $objPHPExcel->getActiveSheet()->setCellValue('G' . $i, $list[$i-2]['haircompany']);
        $objPHPExcel->getActiveSheet()->setCellValue('H' . $i, $list[$i-2]['pay']);
        $objPHPExcel->getActiveSheet()->setCellValue('I' . $i, $list[$i-2]['weight']);
        $objPHPExcel->getActiveSheet()->setCellValue('J' . $i, $list[$i-2]['number']);
        $objPHPExcel->getActiveSheet()->setCellValue('K' . $i, $list[$i-2]['insuredprice']);
        $objPHPExcel->getActiveSheet()->setCellValue('L' . $i, $list[$i-2]['collect']);
        $objPHPExcel->getActiveSheet()->setCellValue('M' . $i, $list[$i-2]['totalpay']);
        $objPHPExcel->getActiveSheet()->setCellValue('N' . $i, $list[$i-2]['article']);
        $objPHPExcel->getActiveSheet()->setCellValue('O' . $i, $list[$i-2]['collectname']);
        $objPHPExcel->getActiveSheet()->setCellValue('P' . $i, $list[$i-2]['collectphone']);
        $objPHPExcel->getActiveSheet()->setCellValue('Q' . $i, $list[$i-2]['collectaddress']);
        $objPHPExcel->getActiveSheet()->setCellValue('R' . $i, $list[$i-2]['collectompany']);
        $objPHPExcel->getActiveSheet()->setCellValue('S' . $i, $list[$i-2]['collectcity']);
        $objPHPExcel->getActiveSheet()->setCellValue('T' . $i, $list[$i-2]['signstaff']);


    }


    /*--------------下面是设置其他信息------------------*/

    $objPHPExcel->getActiveSheet()->setTitle('productaccess');      //设置sheet的名称
    $objPHPExcel->setActiveSheetIndex(0);                   //设置sheet的起始位置
    $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');   //通过PHPExcel_IOFactory的写函数将上面数据写出来

    $PHPWriter = \PHPExcel_IOFactory::createWriter( $objPHPExcel,"Excel2007");

    header('Content-Disposition: attachment;filename="快递信息.xlsx"');
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

    $PHPWriter->save("php://output"); //表示在$path路径下面生成demo.xlsx文件
}
//中文导出结束

//英文导出开始
public function english(){
    $user = session('user');
    //dump($user);exit;
    if(!$user){
        header("Refresh:1;url=login");
    }
   // echo "<script>alert('英文导出开发中')</script>";
   // $this->success('英文导出页面','express');
    $list = db('user')->select();
    //导出
    $path = dirname(__FILE__); //找到当前脚本所在路径
    vendor("PHPExcel.Classes.PHPExcel");
    vendor("PHPExcel.Classes.PHPExcel.Writer.IWriter");
    vendor("PHPExcel.Classes.PHPExcel.Writer.Abstract");
    vendor("PHPExcel.Classes.PHPExcel.Writer.Excel5");
    vendor("PHPExcel.Classes.PHPExcel.Writer.Excel2007");
    vendor("PHPExcel.Classes.PHPExcel.IOFactory");
    $objPHPExcel = new \PHPExcel();
    $objWriter = new \PHPExcel_Writer_Excel5($objPHPExcel);
    $objWriter = new \PHPExcel_Writer_Excel2007($objPHPExcel);


    // 实例化完了之后就先把数据库里面的数据查出来


    // 设置表头信息
    $objPHPExcel->setActiveSheetIndex(0)
        ->setCellValue('A1', 'id')
        ->setCellValue('B1', 'Deliver goods name')
        ->setCellValue('C1', 'Deliver goods  phone')
        ->setCellValue('D1', 'Deliver goods city')
        ->setCellValue('E1', 'Odd Numbers')
        ->setCellValue('F1', 'Deliver goods address')
        ->setCellValue('G1', 'Deliver goods company')
        ->setCellValue('H1', 'freightpay')
        ->setCellValue('I1', 'weight')
        ->setCellValue('J1', 'Number')
        ->setCellValue('K1', 'Insurance')
        ->setCellValue('L1', 'Collect')
        ->setCellValue('M1', 'Total cost')
        ->setCellValue('N1', 'transport Goods')
        ->setCellValue('O1', 'Receipt name')
        ->setCellValue('P1', 'Receipt phone')
        ->setCellValue('Q1', 'Receipt address')
        ->setCellValue('R1', 'Receipt company')
        ->setCellValue('S1', 'Receipt city')
        ->setCellValue('T1', 'Sign in staff');

    /*--------------开始从数据库提取信息插入Excel表中------------------*/

    $i=2;  //定义一个i变量，目的是在循环输出数据是控制行数
    $count = count($list);  //计算有多少条数据
    for ($i = 2; $i <= $count+1; $i++) {
        $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $list[$i-2]['id']);
        $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $list[$i-2]['hairname']);
        $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $list[$i-2]['hairphone']);
        $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $list[$i-2]['haircity']);
        $objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $list[$i-2]['oddnumbers']);
        $objPHPExcel->getActiveSheet()->setCellValue('F' . $i, $list[$i-2]['hairaddress']);
        $objPHPExcel->getActiveSheet()->setCellValue('G' . $i, $list[$i-2]['haircompany']);
        $objPHPExcel->getActiveSheet()->setCellValue('H' . $i, $list[$i-2]['pay']);
        $objPHPExcel->getActiveSheet()->setCellValue('I' . $i, $list[$i-2]['weight']);
        $objPHPExcel->getActiveSheet()->setCellValue('J' . $i, $list[$i-2]['number']);
        $objPHPExcel->getActiveSheet()->setCellValue('K' . $i, $list[$i-2]['insuredprice']);
        $objPHPExcel->getActiveSheet()->setCellValue('L' . $i, $list[$i-2]['collect']);
        $objPHPExcel->getActiveSheet()->setCellValue('M' . $i, $list[$i-2]['totalpay']);
        $objPHPExcel->getActiveSheet()->setCellValue('N' . $i, $list[$i-2]['article']);
        $objPHPExcel->getActiveSheet()->setCellValue('O' . $i, $list[$i-2]['collectname']);
        $objPHPExcel->getActiveSheet()->setCellValue('P' . $i, $list[$i-2]['collectphone']);
        $objPHPExcel->getActiveSheet()->setCellValue('Q' . $i, $list[$i-2]['collectaddress']);
        $objPHPExcel->getActiveSheet()->setCellValue('R' . $i, $list[$i-2]['collectompany']);
        $objPHPExcel->getActiveSheet()->setCellValue('S' . $i, $list[$i-2]['collectcity']);
        $objPHPExcel->getActiveSheet()->setCellValue('T' . $i, $list[$i-2]['signstaff']);


    }


    /*--------------下面是设置其他信息------------------*/

    $objPHPExcel->getActiveSheet()->setTitle('productaccess');      //设置sheet的名称
    $objPHPExcel->setActiveSheetIndex(0);                   //设置sheet的起始位置
    $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');   //通过PHPExcel_IOFactory的写函数将上面数据写出来

    $PHPWriter = \PHPExcel_IOFactory::createWriter( $objPHPExcel,"Excel2007");
    $h = date('Y-m-d_His');
   // echo $h;exit;
    header('Content-Disposition: attachment;filename="Express information.xlsx"');
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

    $PHPWriter->save("php://output"); //表示在$path路径下面生成demo.xlsx文件
}

//英文导出结束
//exel 导出开始

//打印快递开始
public function printing(){
    $user = session('user');
    //dump($user);exit;
    if(!$user){
        header("Refresh:1;url=login");
    }
        $id['id'] = trim($_GET['id']);
    echo "<script>alert('打印快递开发中');location.href='express';</script>";
    //$this->success('打印快递页面','express');
}
//打印快递结束
public function admin(){
    $user = session('user');
    //dump($user);exit;

    if(!$user){
        header("Refresh:1;url=login");
    }
    $res=db('admin')->paginate(10);
    $page =  $res->render();
    $this->assign('page',$page);
    $this->assign('list',$res);
    return $this->fetch();
}

//管理员添加人员开始
public function admin_insert(){
    $user = session('user');
    //dump($user);exit;

    if(!$user){
        header("Refresh:1;url=login");
    }
    $res=db('site')->select();

    $this->assign('list',$res);
    return $this->fetch();
}
public function adminadd(){
    $user = session('user');
    //dump($user);exit;
    if(!$user){
        header("Refresh:1;url=login");
    }
    if(!$_POST) {
        echo "<script>alert('提交不能为空');location.href='admin_insert';</script>";
    }
    $na['name'] = trim($_POST['name']);
    $res = db('admin')->where($na)->find();
    if($na['name'] == $res['name']){
        //return ['code'=>2,'msg'=>'添加账号重复'];
        echo "<script>alert('添加账号重复');location.href='admin_insert';</script>";
    }
    //dump($_POST);exit;
        $data['name'] = trim($_POST['name']);
        $data['password'] = md5(md5(trim($_POST['password'])));
        $data['expresspoint'] = trim($_POST['expresspoint']);
        $data['jurisdiction'] = trim($_POST['jurisdiction']);
        $data['operation'] = session('user.name');
        $data['time'] = time();

    //dump($data);exit;
    $res=db('admin')->insert($data);
    if($res){
        //return ['code'=>1,'msg'=>'添加信息成功'];
        echo "<script>alert('添加成功');location.href='admin';</script>";
    }else{
        //return ['code'=>3,'msg'=>'添加信息失败'];
        echo "<script>alert('添加失败');location.href='admin';</script>";
    }

}
//管理员添加管理人员结束
//管理员编辑管理人员开始
public function admin_det(){
    $user = session('user');
    //dump($user);exit;

    if(!$user){
        header("Refresh:1;url=login");
    }
    if(!$_GET) {
        echo "<script>alert('提交不能为空');location.href='admin_det';</script>";
        //$this->success('提交不能为空', 'express');
    }
    $ress=db('site')->select();
    $id['id']=trim($_GET['id']);
    $res=db('admin')->where($id)->find();
    //dump($res);exit;
    $this->assign('listt',$ress);
    //dump($ress);exit;
    $this->assign('list',$res);
    return $this->fetch();
}
public function adminupdata(){
    $user = session('user');
    //dump($user);exit;
    if(!$user){
        header("Refresh:1;url=login");
    }
    if(!$_POST) {
        echo "<script>alert('提交不能为空');location.href='admin';</script>";
        //$this->success('提交不能为空', 'express');
    }
    $id['id'] = trim($_GET['id']);
    //dump($_POST);exit;
    //$data = $_POST;
    $data['name'] = trim(input('name'));
    if(!$_POST['password'] == "") {
        $data['password'] = md5(md5(trim(input('password'))));
    }
    $data['expresspoint'] = trim(input('expresspoint'));
    $data['jurisdiction'] = trim(input('jurisdiction'));
    $data['operation'] = session('user.name');
    $data['time'] = time();
    //dump($data);exit;
    $res=db('admin')->where($id)->update($data);
    if($res){
        echo "<script>alert('更新信息成功');location.href='admin';</script>";
        //return ['code'=>1,'msg'=>'更新信息成功'];

    }else{
        echo "<script>alert('更新信息失败');location.href='admin';</script>";
        //return ['code'=>0,'msg'=>'更新信息失败'];

    }
}
//管理员编辑管理人员结束
//管理员删除管理人员开始
public function admindelect(){
    $user = session('user');
    //dump($user);exit;

    if(!$user){
        header("Refresh:1;url=login");
    }
    if(!$_GET){
        echo "<script>alert('提交不能为空');location.href='admin';</script>";
        //$this->success('提交不能为空','admin');
    }
    $data['id'] = trim($_GET['id']);
    $res=db('admin')->where($data)->delete();
    if($res){
        echo "<script>alert('删除成功');javascript:history.go(-1);</script>";
        //return ['code'=>1,'msg'=>'删除信息成功'];

    }else{
        echo "<script>alert('删除失败');javascript:history.go(-1);</script>";
        //return ['code'=>0,'msg'=>'删除信息失败'];

    }
}

//管理员删除管理人员结束



    public function site(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }
        $res=db('site')->paginate(10);
        $page =  $res->render();
        $this->assign('page',$page);
        $this->assign('list',$res);
        return $this->fetch();
    }
//管理员快递站点开始
    public function site_insert(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }

        return $this->fetch();
    }
    public function siteadd(){
        $user = session('user');
        //dump($user);exit;
        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_POST) {
            echo "<script>alert('提交不能为空');location.href='site_insert';</script>";
        }
        $na['sitename'] = trim($_POST['sitename']);
        $res = db('site')->where($na)->find();
        if($na['sitename'] == $res['sitename']){
            echo "<script>alert('添加重复');location.href='site_insert';</script>";
        }
        $data['sitename'] = trim($_POST['sitename']);
        $data['siteaddress'] = trim($_POST['siteaddress']);
        $data['time'] = time();
        //dump($data);exit;
        $res=db('site')->insert($data);
        if($res){
            //return ['code'=>1,'msg'=>'添加信息成功'];
            echo "<script>alert('添加成功');location.href='site';</script>";
        }else{
            //return ['code'=>0,'msg'=>'添加信息失败'];
            echo "<script>alert('添加失败');location.href='site';</script>";
        }

    }
//管理员添加快递站点结束
//管理员编辑快递站点开始
    public function site_det(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_GET) {
            echo "<script>alert('提交不能为空');location.href='site_det';</script>";
            //$this->success('提交不能为空', 'express');
        }
        $id['id']=trim($_GET['id']);
        $res=db('site')->where($id)->find();
        //dump($res);exit;
        $this->assign('list',$res);
        return $this->fetch();
    }
    public function siteupdata(){
        $user = session('user');
        //dump($user);exit;
        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_POST) {
            echo "<script>alert('提交不能为空');location.href='site';</script>";
            //$this->success('提交不能为空', 'express');
        }
        $id['id'] = trim($_GET['id']);
        //dump($_POST);exit;
        //$data = $_POST;

        $data['sitename'] = trim(input('sitename'));
        $data['siteaddress'] = trim(input('siteaddress'));
        $data['time'] = time();
        //dump($data);exit;
        $res=db('site')->where($id)->update($data);
        if($res){
            echo "<script>alert('更新信息成功');location.href='site';</script>";
            //return ['code'=>1,'msg'=>'更新信息成功'];

        }else{
            echo "<script>alert('更新信息失败');location.href='site';</script>";
            //return ['code'=>0,'msg'=>'更新信息失败'];

        }
    }
//管理员编辑快递站点结束
//管理员删除快递站点开始
    public function sitedelect(){
        $user = session('user');
        //dump($user);exit;

        if(!$user){
            header("Refresh:1;url=login");
        }
        if(!$_GET){
            echo "<script>alert('提交不能为空');location.href='site';</script>";
        }
        $data['id'] = trim($_GET['id']);
        $res=db('site')->where($data)->delete();
        if($res){
            echo "<script>alert('删除成功');javascript:history.go(-1);</script>";
            //return ['code'=>1,'msg'=>'删除信息成功'];

        }else{
            echo "<script>alert('删除失败');javascript:history.go(-1);</script>";
            //return ['code'=>0,'msg'=>'删除信息失败'];

        }
    }

//管理员删除快递站点结束

}
